package com.sunlong.jiangwei.dao;

import com.sunlong.jiangwei.entity.JwCart;
import com.sunlong.jiangwei.entity.JwSpu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PostMapping;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 孙龙
 * @since 2021-02-19
 */
public interface JwCartMapper extends Mapper<JwCart> {

    @Insert("insert into jw_cart(user_id,spu_str,sku_str,count,status) values(#{cart.userId}," +
            "#{cart.spuStr},#{cart.skuStr},#{cart.count},#{cart.status})")
    void add(@Param("cart") JwCart cart);

    @Select("select * from jw_cart where user_id = #{userId}")
    List<JwCart> list(Long userId);

    @Update("update jw_cart set status = 1 where user_id = #{userId} and sku_str = #{skuStr}")
    void updateByPrimary(Long userId, String skuStr, Integer status);

    @Update("update jw_cart set status = #{status} where cart_id = #{cartId}")
    void updateStatusByCartId(Integer status, Long cartId);
}
